package n皇后问题;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N = 15, n;
    static boolean[] col = new boolean[N];
    static boolean[] dg = new boolean[N * 2];
    static boolean[] udg = new boolean[N * 2];
    static char[][] g = new char[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            Arrays.fill(g[i], '.');
        }
        dfs(0);
    }

    private static void dfs(int u) {
        if (u == n) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.print(g[i][j]);
                }
                System.out.println();
            }
            System.out.println();
            return;
        }
        for (int i = 0; i < n; i++) {
            if (!col[i] && !dg[i - u + n] && !udg[i + u]) {
                col[i] = dg[i - u + n] = udg[i + u] = true;
                g[u][i] = 'Q';
                dfs(u + 1);
                col[i] = dg[i - u + n] = udg[i + u] = false;
                g[u][i] = '.';
            }
        }
    }
}
